package org.example.file;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class FileCopyExample {
    public static final String FILE_PATH = "C:\\Users\\JohnConnor\\Documents\\Downloads\\catalina.out";
    public static final String TARGET_FILE_PATH = "C:\\Users\\JohnConnor\\Documents\\Downloads\\MyDirect\\a\\b\\c\\d\\e\\catalina1.out";
    public static void main(String[] args) throws IOException {
        test3();
    }

    static void test1() throws IOException {
        Files.copy(Paths.get(FILE_PATH),Paths.get(TARGET_FILE_PATH));
    }

    static void test2() throws IOException {
        Path targetPath = Paths.get(TARGET_FILE_PATH);
        Path parent = targetPath.getParent();
        if (parent != null) {
            if (Files.notExists(parent)) {
                Files.createDirectories(parent);
            }
        }
        Files.copy(Paths.get(FILE_PATH),Paths.get(TARGET_FILE_PATH));
    }

    static void test3() throws IOException {
        File sourceFile = new File(FILE_PATH);
        File toFile = new File(TARGET_FILE_PATH);
        /*FileUtils.copyFile(sourceFile,toFile);*/
        com.google.common.io.Files.copy(sourceFile,toFile);
    }
}
